/**
 * Constructor for a complex number.
 * @param Number real the real part of the complex number.
 * @param Number imaginary the imaginary part of the complex number.
 * @constructor
 */
function Complex(real, imaginary) {
    this.real = real;
    this.imaginary = imaginary;
}

Complex.prototype = {
    /**
     * The real part of the complex number.
     * @type Number
     */
    real: 0,
    /**
     * The imaginary part of the complex number.
     * @type Number
     */
    imaginary: 0,
    /**
     * Adds this to another complex number, returning the
     * result. Implementation derivated from the definition.
     * @param Complex complex another complex number.
     * @return Complex the sum of this with the parameter.
     */
    add: function(complex) {
        return new Complex(
            this.real + complex.real,
            this.imaginary + complex.imaginary);
    },
    /**
     * Multiplies this to another compelx number, returning
     * the result. Implementation derivated from the definition.
     * @param Complex complex another complex number.
     * @return Complex the product of this with the parameter.
     */
    mul: function(complex) {
        return new Complex(
            this.real * complex.real - this.imaginary * this.imaginary,
            this.real * complex.imaginary + complex.real * this.imaginary);
    },
    /**
     * Complex exponential. Returns e to the power this.
     * Implementation derivated from euler's formula:
     * e^(xi) = cos(x) + i * sin(x)
     * @return Complex e to the power this.
     */
    exp: function() {
        return new Complex(
            Math.exp(this.real) * Math.cos(this.imaginary),
            Math.exp(this.real) * Math.sin(this.imaginary));
    }
}